# @Time    :2025/4/13 9:54
class Stack:
    """后进先出，基于数组，链表也可以"""
    def __init__(self):
        self.__size = 0
        self.__items = []
    # def __str__(self):
    #

    @property
    def size(self):
        return self.__size

    def is_impty(self):
        return self.__size == 0

    def push(self, item):
        """入栈"""
        self.__items.append(item)
        self.__size += 1

    def pop(self):
        if self.__size == 0:
            raise Exception("没有元素")
        else:
            # return self.items.pop()
            item = self.__items[self.__size - 1]
            del self.__items[self.__size - 1]
            self.__size -= 1
            return item

    def peek(self):
        if self.__size == 0:
            raise Exception("没有元素")
        else:
            return self.__items[self.__size - 1]


s = Stack()
# s.push(3)
# s.push(6)
# s.push(4)
# s.push(8)

print(s.is_impty())
print(s.pop())
print(s.size)

